package com.googlecode.c4e.ui.actions.internal;

import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.model.IWorkbenchAdapter;

import com.googlecode.c4e.api.model.BuildResult;

public class BuildLogContent implements IStorageEditorInput {

	private String name;
	private IStorage storage;

	public BuildLogContent(BuildResult buildResult) {
		this.name = buildResult.getProject().getArtifactId() + "-"
				+ buildResult.getProject().getVersion() + "-"
				+ buildResult.getBuildNumber() + ".log";
		storage = new BuildLogContentStorage(name, buildResult.getOutput());
	}

	public boolean exists() {
		return true;
	}

	public ImageDescriptor getImageDescriptor() {
		return null;
	}

	public String getName() {
		return name;
	}

	public IPersistableElement getPersistable() {
		return null;
	}

	public String getToolTipText() {
		return name;
	}

	public Object getAdapter(Class adapter) {
		if (adapter == IWorkbenchAdapter.class) {
			return this;
		}
		return null;
	}

	public IStorage getStorage() throws CoreException {
		return storage;
	}

}
